package com.qianguo.shop.activity;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.eva.androidlibrary.image.ImageLoader;
import com.eva.androidlibrary.utils.IconfontUtil;
import com.eva.androidlibrary.widget.mdedittext.MaterialEditText;
import com.qianguo.shop.R;
import com.qianguo.shop.base.BaseChooseImageActivity;
import com.eva.androidlibrary.icon.FruitIcon;

import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

import java.io.File;

/**
 * 实名认证
 *
 * @author GUXIA318
 * @date 2015-10-28 18:37
 */
@EActivity(R.layout.activity_real_name)
public class RealNameAuthActivity extends BaseChooseImageActivity {

    @ViewById(R.id.real_name_camera_icon_tv)
    TextView mTvCamera;
    @ViewById(R.id.real_name_edit_text)
    MaterialEditText mEdtName;
    @ViewById(R.id.real_name_id_card_edit_text)
    MaterialEditText mEdtIDCard;
    @ViewById(R.id.real_name_id_card_photo_iv)
    ImageView mImgIDCard;

    private File mPicFile;

    public static void jumpToRealName(Context context) {
        context.startActivity(new Intent(context, com.qianguo.shop.activity.RealNameAuthActivity_.class));
    }

    @Override
    protected String getToolbarTitle() {
        return getString(R.string.real_name);
    }

    @Override
    protected void initializeUI() {
        IconfontUtil.setIcon(this, mTvCamera, FruitIcon.ICON_CAMERA);
    }

    @Click(R.id.real_name_scan_id_card_layout)
    void clickScan() {
        ScanIDCardActivity.jumpToScanIDCard(this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        if (intent != null) {
            String picPath = intent.getStringExtra("picPath");
            String realName = intent.getStringExtra("realName");
            String idNum = intent.getStringExtra("idNum");
            String tips = "";
            if(TextUtils.isEmpty(picPath))
                return;
            if(!mEdtName.getText().equals(realName)){
                tips = "您填写的信息与识别的结果不符合,将以识别的信息为准。";
            }
            if(!mEdtIDCard.getText().equals(idNum)) {
                tips = "您填写的信息好像与识别的结果不符合,将以识别的信息为准。";
            }
            mEdtName.setText(realName);
            mEdtIDCard.setText(idNum);
            mPicFile = new File(picPath);
            ImageLoader.getInstance(this).loadImage(this, mImgIDCard, picPath);
        }
    }
}
